<!DOCTYPE html>
<html lang="en">
	<head>
		<title>MAX FACTORX</title>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="./css/css.css">
	</head>
  <body class="login_bg">
  	<!--[if lt IE 8]>
	<style type="text/css">
		body{
			padding:0;
			margin:0;
		}
		.no-supper{
			min-height: 100px;
			text-align: center;
			line-height:100px;
			background-color:#FFBD91;
			color:#000;
		}

		.no-supper a{
			color:#45a7ff;
		}
	</style>

	<div class="no-supper">
		您的浏览器版本较低，可能存在安全风险，请升级到最新IE浏览器。亦可下载 <a href="https://chrome.google.com/" target="_blank">Google Chrome</a>
	</div>
	<![endif]-->
  	<div class="login_box">
  		<h3></h3>
  		<div class="login_text">
  			<span class="error" id="error"></span>
  			<p>
  				<label for="" class="uname"></label>
  				<input type="text" id="uname">
  			</p>
  			<p>
  				<label for="" class="pwd"></label>
  				<input type="password" id="pwd">
  			</p>
  			<a href="javascript:;" class="login_sub" id="log">登&nbsp;录</a>
  		</div>
  	</div>
  </body>
  <script src="jquery.min.js"></script>
  <script>
  ;(function(){
    var name,pwd,url,
    // domain='http://maxfactor.data.social-touch.com';
//    domain=window.location.hostname.match(/\d+/) ? "http://115.28.164.153:9081" : "http://115.28.164.153:9081";
     domain='http://maxfactor.data.social-touch.com/dataApi';
    document.getElementById('log').onclick = function(){
      name = document.getElementById('uname').value;
      pwd = document.getElementById('pwd').value;
      url = domain + '/auth';
      $.ajax({
        url:url,
        data:{'username':name,'password':pwd},
        type:'post',
        success:function(res){
          if(res.status == 200){
            var data = res.data
            setCookie('mname',data.username,1);
            setCookie('userid',data.id,1);
            setCookie('Authorization',data.token,1);
            location.href='/';
          }else{
            document.getElementById('error').innerHTML = '用户名或密码错误';
            console.log(res.msg)
          }
        }
      })
    }

     document.onkeydown = function(event){
            if (event.keyCode == "13") {
                document.getElementById("log").click();
                return false;
            }

        };
  })()


  	//设置cookie
    function setCookie(cname, cvalue, exdays) {
        var d = new Date();
        var path = '/';
        d.setTime(d.getTime() + (exdays*24*60*60*1000));
        var expires = "expires="+d.toUTCString();
        document.cookie = cname + "=" + cvalue + "; " + expires+"; path=" + path ;
    }
    //获取cookie
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') c = c.substring(1);
            if (c.indexOf(name) != -1) return c.substring(name.length, c.length);
        }
        return "";
    }
  </script>
  <!-- <script src="/webpack-dev-server.js"></script> -->
</html>
